# Contributor: Stefan Wagner <stw@bit-strickerei.de>
# Maintainer: Stefan Wagner <stw@bit-strickerei.de>
pkgname=avr-libc
pkgver=2.1.0
_atmelver=3.7.0.1796
pkgrel=4
pkgdesc="The C runtime library for the AVR family of microcontrollers"
url="https://github.com/avrdudes/avr-libc"
depends="gcc-avr"
makedepends="autoconf automake"
arch="x86_64 ppc64le aarch64 x86"
license="BSD-3-Clause"
subpackages="$pkgname-doc"
builddir="$srcdir/$pkgname-$pkgname-${pkgver//./_}-release"
source="
	avr-libc-$pkgver.tar.gz::https://github.com/avrdudes/avr-libc/archive/refs/tags/avr-libc-${pkgver//./_}-release.tar.gz
	https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/avr8-gnu-toolchain-$_atmelver-linux.any.x86_64.tar.gz
	"

prepare() {
	default_prepare

	# Updating I/O header files from Atmel toolchain
	find ../avr8-gnu-toolchain-linux_x86_64/avr/include/avr \
		-name 'io*.h' \
		-exec cp {} include/avr/ \;
}

build() {
	./bootstrap
	CC=avr-gcc ./configure \
		--build="$(/bin/sh config.guess)" \
		--host=avr \
		--prefix=/usr
	make
}

package() {
	make install DESTDIR="$pkgdir"
	if [ -d "$pkgdir"/usr/lib64 ]; then
		mv "$pkgdir"/usr/lib64/* "$pkgdir"/usr/lib/
		rmdir "$pkgdir"/usr/lib64
	fi
}

sha512sums="
b9b5702e3770fb76a9b6b405a744120c2b127032424caff6e002b4d21a04a293607da2bb36cb797cbcdf0209e851e858a192d9b2c812e6c6bf8e54ec18ae1beb  avr-libc-2.1.0.tar.gz
25739df6277f644cac00460f5ac42707f43a841902f23fb7632c9c7aeec89302340b3cc7c4e90a994e400a1d6f6f37804fee0c5cd95320e9d725a24de8127a1f  avr8-gnu-toolchain-3.7.0.1796-linux.any.x86_64.tar.gz
"
